unit Class_DAYS_TOTL;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TDAYSTOTL=class(TUniEngine)
  private
    FDAYSSTAX: Integer;
    FDAYSENDX: Integer;
    FDOCTIDEX: Integer;
    FDAYSTOTL: Extended;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DAYSSTAX: Integer read FDAYSSTAX write FDAYSSTAX;
    property DAYSENDX: Integer read FDAYSENDX write FDAYSENDX;
    property DOCTIDEX: Integer read FDOCTIDEX write FDOCTIDEX;
    property DAYSTOTL: Extended read FDAYSTOTL write FDAYSTOTL;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ADAYSTOTL:TDAYSTOTL):TDAYSTOTL;overload;        
    class procedure CopyIt(ADAYSTOTL:TDAYSTOTL;var Result:TDAYSTOTL);overload;       
  end;

implementation

{ TDAYSTOTL }
procedure TDAYSTOTL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('DAYS_STAX').Value := DAYSSTAX;
        ParamByName('DAYS_ENDX').Value := DAYSENDX;
        ParamByName('DOCT_IDEX').Value := DOCTIDEX;
        ParamByName('DAYS_TOTL').Value := DAYSTOTL; 
      end;
      otEdit:
      begin
        ParamByName('DAYS_STAX').Value := DAYSSTAX;
        ParamByName('DAYS_ENDX').Value := DAYSENDX;
        ParamByName('DOCT_IDEX').Value := DOCTIDEX;
        ParamByName('DAYS_TOTL').Value := DAYSTOTL; 
      end;  
      otDelt:
      begin
        ParamByName('DAYS_STAX').Value := DAYSSTAX;
        ParamByName('DAYS_ENDX').Value := DAYSENDX;
 
      end;  
    end;
  end;
end;

function TDAYSTOTL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_DAYS_TOTL',['DAYS_STAX',DAYSSTAX,'DAYS_ENDX',DAYSENDX],AUniConnection);
end;

function TDAYSTOTL.GetNextIdex: Integer;
begin

end;

function TDAYSTOTL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TDAYSTOTL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_DAYS_TOTL WHERE   DAYS_STAX=:DAYS_STAX AND DAYS_ENDX=:DAYS_ENDX';
end;

function TDAYSTOTL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_DAYS_TOTL'
         +'    ( DAYS_STAX, DAYS_ENDX, DOCT_IDEX, DAYS_TOTL)'
         +'    VALUES'
         +'    (:DAYS_STAX,:DAYS_ENDX,:DOCT_IDEX,:DAYS_TOTL)';
end;

function TDAYSTOTL.GetStrsIndex: string;
begin
  Result:=Format('%D-%D',[DAYSSTAX,DAYSENDX]);
end;

function TDAYSTOTL.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_DAYS_TOTL SET'
         +'    DOCT_IDEX=:DOCT_IDEX,'
         +'    DAYS_TOTL=:DAYS_TOTL'
         +'    WHERE DAYS_STAX=:DAYS_STAX'
         +'    AND   DAYS_ENDX=:DAYS_ENDX';
end;

constructor TDAYSTOTL.Create;
begin

end;

destructor TDAYSTOTL.Destroy;
begin

  inherited;
end;

class function TDAYSTOTL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TDAYSTOTL.Create;
  with TDAYSTOTL(Result) do
  begin
    //DAYSSTAX:=AUniQuery.FieldByName('DAYS_STAX').AsInteger;
    //DAYSENDX:=AUniQuery.FieldByName('DAYS_ENDX').AsInteger;
    DOCTIDEX:=AUniQuery.FieldByName('DOCT_IDEX').AsInteger;
    DAYSTOTL:=AUniQuery.FieldByName('DAYS_TOTL').AsFloat;
  end;  
end;

class procedure TDAYSTOTL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TDAYSTOTL(Result) do
  begin
    //DAYSSTAX:=AUniQuery.FieldByName('DAYS_STAX').AsInteger;
    //DAYSENDX:=AUniQuery.FieldByName('DAYS_ENDX').AsInteger;
    DOCTIDEX:=AUniQuery.FieldByName('DOCT_IDEX').AsInteger;
    DAYSTOTL:=AUniQuery.FieldByName('DAYS_TOTL').AsFloat;
  end;  
end;

class function  TDAYSTOTL.CopyIt(ADAYSTOTL: TDAYSTOTL): TDAYSTOTL;
begin
  Result:=TDAYSTOTL.Create;
  TDAYSTOTL.CopyIt(ADAYSTOTL,Result)
end;

class procedure TDAYSTOTL.CopyIt(ADAYSTOTL:TDAYSTOTL;var Result:TDAYSTOTL);
begin
  if Result=nil then Exit;
  Result.DAYSSTAX:=ADAYSTOTL.DAYSSTAX;
  Result.DAYSENDX:=ADAYSTOTL.DAYSENDX;
  Result.DOCTIDEX:=ADAYSTOTL.DOCTIDEX;
  Result.DAYSTOTL:=ADAYSTOTL.DAYSTOTL;
end;

end.

